﻿<UserControl x:Class="Ops.Mpc.ExampleApplication.Polling.Controls.PollingItemControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:presenters="clr-namespace:Ops.Mpc.Presenters;assembly=Ops.Mpc"
    xmlns:controllers="clr-namespace:Ops.Mpc.Controllers;assembly=Ops.Mpc"   
    xmlns:states="clr-namespace:Ops.Mpc.States;assembly=Ops.Mpc"   
    xmlns:pollingitemmodels="clr-namespace:Ops.Mpc.ExampleApplication.Polling.Controls.Models"
    xmlns:pollingitemsactions="clr-namespace:Ops.Mpc.ExampleApplication.Polling.Controls.Actions"          
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Border BorderBrush="DarkBlue" BorderThickness="1" Height="150" Width="150" CornerRadius="10"  >
        <Border.Clip>
            <RectangleGeometry Rect="0,0,150,150"/>
        </Border.Clip>
        <presenters:Presenter x:Name="Presenter1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
            <controllers:Controller>
                <controllers:Controller.StateTransitions>
                    <states:StateTransition From="StoppedState" To="PollingState" Transition="Up" />
                    <states:StateTransition To="StoppedState" From="PollingState" Transition="Down" />
                </controllers:Controller.StateTransitions>
                <controllers:Controller.Models>
                    <pollingitemmodels:PollingItemModel ItemName="PollingItemModel"/>
                </controllers:Controller.Models>
                <controllers:Controller.States>
                    <states:State ItemName="StoppedState" AutoRun="True" >
                        <states:StateTemplate>
                            <HyperlinkButton Content="{Binding Models[PollingItemModel].Name,StringFormat='Start {0}'}" Command="{Binding StateActions[StartStateAction]}" VerticalAlignment="Center" HorizontalAlignment="Center"  />
                        </states:StateTemplate>
                        <states:State.StateActions>
                            <pollingitemsactions:InitializationStateAction ItemName="InitializationStateAction" />
                            <states:NoOperationStateAction ItemName="StartStateAction" NextStateItemName="PollingState" />
                        </states:State.StateActions>
                    </states:State>
                    <states:State ItemName="PollingState" >
                        <states:StateTemplate>
                            <Grid>
                                <TextBlock Foreground="Blue" Text="{Binding Models[PollingItemModel].Count}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                <HyperlinkButton Content="{Binding Models[PollingItemModel].Name,StringFormat='Stop {0}'}"  Command="{Binding StateActions[StopStateAction]}" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="5"/>
                            </Grid>
                        </states:StateTemplate>
                        <states:State.StateActions>
                            <pollingitemsactions:PollStateAction ItemName="PollStateAction" StartTimeSeconds="1" PollTimeIntervalSeconds="1"/>
                            <states:NoOperationStateAction ItemName="StopStateAction" NextStateItemName="StoppedState" />
                        </states:State.StateActions>
                    </states:State>
                </controllers:Controller.States>
            </controllers:Controller>
        </presenters:Presenter>
    </Border>
</UserControl>
